from utils.readUtil import *
class UiFunction():
    def initUiFunction(self):
        pass
    def readAccount(self):
        try:
            context = readPsdFile('log/account.txt')
            self.accounts = {}
            if len(context) <= 0:
                return
            for i in context:
                if len(i) < 8:
                    continue
                userid, psd = i.split('-')
                self.accounts[userid] = psd
                self.acoountCombox.addItem(str(userid))
            print(self.accounts)
            if len(self.accounts) >= 1:
                for i in self.accounts.keys():
                    userid, psd = i,self.accounts[i]
                    break
                self.userIdInput.setText(str(userid))
                self.userPswInput.setText(str(psd).replace("\x07",""))
        except:
            self.terminal.append("读取数据的过程发生错误,请尝试格式化数据文件")
    def dealAccount(self):
        return
        userid = self.acoountCombox.currentText()
        if len(userid) == 0:
            return
        self.accounts.pop(userid)
        context = []
        for i in self.accounts.keys():
            context.append(i + "-" + self.accounts[i])
        overWritePsdFile('log/account.txt',context)
    def flashIpMacInfo(self):
        self.uiGetNetInfo()
        if len(self.user) <= 2:
            self.terminal.append("获取信息失败")
            return
        self.ipLabel.setText("当前Ip  " + str(self.user['wlanuserip']))
        self.macLabel.setText("当前Mac  " + str(self.user['mac']))
        self.macInput.setText(self.user['mac'])
    def flashAcPsdInfo(self):
        userid = self.acoountCombox.currentText()
        psd = self.accounts[userid]
        self.userIdInput.setText(str(userid))
        self.userPswInput.setText(str(psd))

